﻿using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LunarSF.SHomeWorkshop.LunarMarkdownEditor.Widgets.MindMap
{
    /// <summary>
    /// MindmapSettingsDialog.xaml 的交互逻辑
    /// </summary>
    public partial class MindmapSettingsDialog : MetroWindow
    {
        public MindmapSettingsDialog()
        {
            InitializeComponent();

            mmvLight.IsToolBarVisible = false;
            mmvDark.IsToolBarVisible = false;

            this.Loaded += MindmapSettingsDialog_Loaded;

            InitBrushPickerComboBoxes();
            LoadSettings();
        }

        private BrushPickerComboBox cmbLightThemeMapBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5,5,5,0), Height= 24, };
        private BrushPickerComboBox cmbLightThemeParentTitleBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbLightThemeCurrentTitleBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbLightThemeSubTitleBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbLightThemeTitleForeground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbLightThemeTitleLinkStroke = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbLightThemeTitleSelectionBox = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };

        private BrushPickerComboBox cmbDartThemeMapBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbDartThemeParentTitleBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbDartThemeCurrentTitleBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbDartThemeSubTitleBackground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbDartThemeTitleForeground = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbDartThemeTitleLinkStroke = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };
        private BrushPickerComboBox cmbDartThemeTitleSelectionBox = new BrushPickerComboBox() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(5, 5, 5, 0), Height = 24, };

        private void InitBrushPickerComboBoxes()
        {
            Grid.SetRow(cmbLightThemeMapBackground, 1);
            Grid.SetRow(cmbLightThemeParentTitleBackground, 3);
            Grid.SetRow(cmbLightThemeCurrentTitleBackground, 5);
            Grid.SetRow(cmbLightThemeSubTitleBackground, 7);
            Grid.SetRow(cmbLightThemeTitleForeground, 9);
            Grid.SetRow(cmbLightThemeTitleLinkStroke, 11);
            Grid.SetRow(cmbLightThemeTitleSelectionBox, 13);

            gridLight.Children.Add(cmbLightThemeMapBackground);
            gridLight.Children.Add(cmbLightThemeParentTitleBackground);
            gridLight.Children.Add(cmbLightThemeCurrentTitleBackground);
            gridLight.Children.Add(cmbLightThemeSubTitleBackground);
            gridLight.Children.Add(cmbLightThemeTitleForeground);
            gridLight.Children.Add(cmbLightThemeTitleLinkStroke);
            gridLight.Children.Add(cmbLightThemeTitleSelectionBox);

            Grid.SetRow(cmbDartThemeMapBackground, 1);
            Grid.SetRow(cmbDartThemeParentTitleBackground, 3);
            Grid.SetRow(cmbDartThemeCurrentTitleBackground, 5);
            Grid.SetRow(cmbDartThemeSubTitleBackground, 7);
            Grid.SetRow(cmbDartThemeTitleForeground, 9);
            Grid.SetRow(cmbDartThemeTitleLinkStroke, 11);
            Grid.SetRow(cmbDartThemeTitleSelectionBox, 13);

            gridDark.Children.Add(cmbDartThemeMapBackground);
            gridDark.Children.Add(cmbDartThemeParentTitleBackground);
            gridDark.Children.Add(cmbDartThemeCurrentTitleBackground);
            gridDark.Children.Add(cmbDartThemeSubTitleBackground);
            gridDark.Children.Add(cmbDartThemeTitleForeground);
            gridDark.Children.Add(cmbDartThemeTitleLinkStroke);
            gridDark.Children.Add(cmbDartThemeTitleSelectionBox);

            cmbLightThemeMapBackground.SelectionChanged += CmbLightThemeMapBackground_SelectionChanged;
            cmbLightThemeParentTitleBackground.SelectionChanged += CmbLightThemeParentTitleBackground_SelectionChanged;
            cmbLightThemeCurrentTitleBackground.SelectionChanged += CmbLightThemeCurrentTitleBackground_SelectionChanged;
            cmbLightThemeSubTitleBackground.SelectionChanged += CmbLightThemeSubTitleBackground_SelectionChanged;
            cmbLightThemeTitleForeground.SelectionChanged += CmbLightThemeTitleForeground_SelectionChanged;
            cmbLightThemeTitleLinkStroke.SelectionChanged += CmbLightThemeTitleLinkStroke_SelectionChanged;
            cmbLightThemeTitleSelectionBox.SelectionChanged += CmbLightThemeTitleSelectionBox_SelectionChanged;
            cmbDartThemeMapBackground.SelectionChanged += CmbDartThemeMapBackground_SelectionChanged;
            cmbDartThemeParentTitleBackground.SelectionChanged += CmbDartThemeParentTitleBackground_SelectionChanged;
            cmbDartThemeCurrentTitleBackground.SelectionChanged += CmbDartThemeCurrentTitleBackground_SelectionChanged;
            cmbDartThemeSubTitleBackground.SelectionChanged += CmbDartThemeSubTitleBackground_SelectionChanged;
            cmbDartThemeTitleForeground.SelectionChanged += CmbDartThemeTitleForeground_SelectionChanged;
            cmbDartThemeTitleLinkStroke.SelectionChanged += CmbDartThemeTitleLinkStroke_SelectionChanged;
            cmbDartThemeTitleSelectionBox.SelectionChanged += CmbDartThemeTitleSelectionBox_SelectionChanged;
        }

        private void CmbDartThemeTitleSelectionBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvDark.TitleDefaultActiveBrush = Brushes.Crimson;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvDark.TitleDefaultActiveBrush = bpcbi.BrushInfo.Brush;
        }

        private void CmbDartThemeTitleLinkStroke_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvDark.TitleLinkStroke = Brushes.White;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvDark.TitleLinkStroke = bpcbi.BrushInfo.Brush;
        }

        private void CmbDartThemeTitleForeground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvDark.TitleDefaultForeground = Brushes.Black;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvDark.TitleDefaultForeground = bpcbi.BrushInfo.Brush;
        }

        private void CmbDartThemeSubTitleBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvDark.ChildTitleDefaultBackground = Brushes.White;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvDark.ChildTitleDefaultBackground = bpcbi.BrushInfo.Brush;
        }

        private void CmbDartThemeCurrentTitleBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvDark.TitleDefaultBackground = Brushes.LightBlue;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvDark.TitleDefaultBackground = bpcbi.BrushInfo.Brush;
        }

        private void CmbDartThemeParentTitleBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvDark.AncestorsTitleDefaultBackground = Brushes.BurlyWood;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvDark.AncestorsTitleDefaultBackground = bpcbi.BrushInfo.Brush;
        }

        private void CmbDartThemeMapBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvDark.MainCanvas.Background = BrushManager.GetBrush("BlackSmoke");
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvDark.MainCanvas.Background = bpcbi.BrushInfo.Brush;
        }

        private void CmbLightThemeTitleSelectionBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvLight.TitleDefaultActiveBrush = Brushes.SandyBrown;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvLight.TitleDefaultActiveBrush = bpcbi.BrushInfo.Brush;
        }

        private void CmbLightThemeTitleLinkStroke_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvLight.TitleLinkStroke = Brushes.Black;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvLight.TitleLinkStroke = bpcbi.BrushInfo.Brush;
        }

        private void CmbLightThemeTitleForeground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvLight.TitleDefaultForeground = Brushes.White;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvLight.TitleDefaultForeground = bpcbi.BrushInfo.Brush;
        }

        private void CmbLightThemeSubTitleBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvLight.ChildTitleDefaultBackground = Brushes.Black;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvLight.ChildTitleDefaultBackground = bpcbi.BrushInfo.Brush;
        }

        private void CmbLightThemeCurrentTitleBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvLight.TitleDefaultBackground = Brushes.Crimson;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvLight.TitleDefaultBackground = bpcbi.BrushInfo.Brush;
        }

        private void CmbLightThemeParentTitleBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvLight.AncestorsTitleDefaultBackground = Brushes.CornflowerBlue;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvLight.AncestorsTitleDefaultBackground = bpcbi.BrushInfo.Brush;
        }

        private void CmbLightThemeMapBackground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if((sender as BrushPickerComboBox).SelectedIndex < 0)
            {
                mmvLight.MainCanvas.Background = Brushes.WhiteSmoke;
                return;
            }

            var si = (sender as BrushPickerComboBox).SelectedItem;
            var bpcbi = (si == null ? null : si as BrushPickerComboBoxItem);
            mmvLight.MainCanvas.Background = bpcbi.BrushInfo.Brush;
        }

        private void LoadSettings()
        {
            var val01 = App.WorkspaceConfigManager.Get("Mindmap-Light-ThemeMapBackground");
            var val02 = App.WorkspaceConfigManager.Get("Mindmap-Light-ThemeParentTitleBackground");
            var val03 = App.WorkspaceConfigManager.Get("Mindmap-Light-ThemeCurrentTitleBackground");
            var val04 = App.WorkspaceConfigManager.Get("Mindmap-Light-ThemeSubTitleBackground");
            var val05 = App.WorkspaceConfigManager.Get("Mindmap-Light-ThemeTitleForeground");
            var val06 = App.WorkspaceConfigManager.Get("Mindmap-Light-ThemeTitleLinkStroke");
            var val07 = App.WorkspaceConfigManager.Get("Mindmap-Light-ThemeTitleSelectionBox");
            var val08 = App.WorkspaceConfigManager.Get("Mindmap-Dart-ThemeMapBackground");
            var val09 = App.WorkspaceConfigManager.Get("Mindmap-Dart-ThemeParentTitleBackground");
            var val10 = App.WorkspaceConfigManager.Get("Mindmap-Dart-ThemeCurrentTitleBackground");
            var val11 = App.WorkspaceConfigManager.Get("Mindmap-Dart-ThemeSubTitleBackground");
            var val12 = App.WorkspaceConfigManager.Get("Mindmap-Dart-ThemeTitleForeground");
            var val13 = App.WorkspaceConfigManager.Get("Mindmap-Dart-ThemeTitleLinkStroke");
            var val14 = App.WorkspaceConfigManager.Get("Mindmap-Dart-ThemeTitleSelectionBox");

            if (string.IsNullOrEmpty(val01)) { cmbLightThemeMapBackground.Select(mmvLight.MainCanvas.Background); } else { cmbLightThemeMapBackground.Select(LoadSetting(val01)); };
            if (string.IsNullOrEmpty(val02)) { cmbLightThemeParentTitleBackground.Select(mmvLight.AncestorsTitleDefaultBackground); } else { cmbLightThemeParentTitleBackground.Select(LoadSetting(val02)); };
            if (string.IsNullOrEmpty(val03)) { cmbLightThemeCurrentTitleBackground.Select(mmvLight.TitleDefaultBackground); } else { cmbLightThemeCurrentTitleBackground.Select(LoadSetting(val03)); };
            if (string.IsNullOrEmpty(val04)) { cmbLightThemeSubTitleBackground.Select(mmvLight.ChildTitleDefaultBackground); } else { cmbLightThemeSubTitleBackground.Select(LoadSetting(val04)); };
            if (string.IsNullOrEmpty(val05)) { cmbLightThemeTitleForeground.Select(mmvLight.TitleDefaultForeground); } else { cmbLightThemeTitleForeground.Select(LoadSetting(val05)); };
            if (string.IsNullOrEmpty(val06)) { cmbLightThemeTitleLinkStroke.Select(mmvLight.TitleLinkStroke); } else { cmbLightThemeTitleLinkStroke.Select(LoadSetting(val06)); };
            if (string.IsNullOrEmpty(val07)) { cmbLightThemeTitleSelectionBox.Select(mmvLight.TitleDefaultActiveBrush); } else { cmbLightThemeTitleSelectionBox.Select(LoadSetting(val07)); };
            if (string.IsNullOrEmpty(val08)) { cmbDartThemeMapBackground.Select(BrushManager.GetBrush("BlackSmoke")); } else { cmbDartThemeMapBackground.Select(LoadSetting(val08)); };
            if (string.IsNullOrEmpty(val09)) { cmbDartThemeParentTitleBackground.Select(mmvDark.AncestorsTitleDefaultBackground); } else { cmbDartThemeParentTitleBackground.Select(LoadSetting(val09)); };
            if (string.IsNullOrEmpty(val10)) { cmbDartThemeCurrentTitleBackground.Select(mmvDark.TitleDefaultBackground); } else { cmbDartThemeCurrentTitleBackground.Select(LoadSetting(val10)); };
            if (string.IsNullOrEmpty(val11)) { cmbDartThemeSubTitleBackground.Select(mmvDark.ChildTitleDefaultBackground); } else { cmbDartThemeSubTitleBackground.Select(LoadSetting(val11)); };
            if (string.IsNullOrEmpty(val12)) { cmbDartThemeTitleForeground.Select(mmvDark.TitleDefaultForeground); } else { cmbDartThemeTitleForeground.Select(LoadSetting(val12)); };
            if (string.IsNullOrEmpty(val13)) { cmbDartThemeTitleLinkStroke.Select(mmvDark.TitleLinkStroke); } else { cmbDartThemeTitleLinkStroke.Select(LoadSetting(val13)); };
            if (string.IsNullOrEmpty(val14)) { cmbDartThemeTitleSelectionBox.Select(mmvDark.TitleDefaultActiveBrush); } else { cmbDartThemeTitleSelectionBox.Select(LoadSetting(val14)); };
        }

        private Brush LoadSetting(string brushEnName)
        {
            return BrushManager.GetBrush(brushEnName);
        }

        private void MindmapSettingsDialog_Loaded(object sender, RoutedEventArgs e)
        {
            btnLoadSample_Click(sender, e);
        }

        private void btnLoadSample_Click(object sender, RoutedEventArgs e)
        {
            var treeTables = new List<List<string>>();
            var treeTable = new List<string>();
            treeTable.Add("！ 上级节点");
            treeTable.Add("！└当前节点");
            treeTable.Add("！　├下级节点1");
            treeTable.Add("！　├下级节点2");
            treeTable.Add("！　├下级节点3");
            treeTable.Add("！　├下级节点4");
            treeTable.Add("！　└下级节点5");
            treeTables.Add(treeTable);

            var treeElements = TreeElement.ParseRootTreeElementsFromTreeTables(treeTables, out List<TreeElement> allElements, null);

            mmvLight.RootElements =
                mmvDark.RootElements = treeElements;

            mmvLight.DisplayMindMap(treeElements[0].Children[0]);
            mmvDark.DisplayMindMap(treeElements[0].Children[0]);
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            var mmvLight = Globals.MainWindow.mindMapView;
            var mmvDark = Globals.MainWindow.mindMapView2;

            var bsh01 = cmbLightThemeMapBackground.SelectBrush;
            var bsh02 = cmbLightThemeParentTitleBackground.SelectBrush;
            var bsh03 = cmbLightThemeCurrentTitleBackground.SelectBrush;
            var bsh04 = cmbLightThemeSubTitleBackground.SelectBrush;
            var bsh05 = cmbLightThemeTitleForeground.SelectBrush;
            var bsh06 = cmbLightThemeTitleLinkStroke.SelectBrush;
            var bsh07 = cmbLightThemeTitleSelectionBox.SelectBrush;

            var bsh08 = cmbDartThemeMapBackground.SelectBrush;
            var bsh09 = cmbDartThemeParentTitleBackground.SelectBrush;
            var bsh10 = cmbDartThemeCurrentTitleBackground.SelectBrush;
            var bsh11 = cmbDartThemeSubTitleBackground.SelectBrush;
            var bsh12 = cmbDartThemeTitleForeground.SelectBrush;
            var bsh13 = cmbDartThemeTitleLinkStroke.SelectBrush;
            var bsh14 = cmbDartThemeTitleSelectionBox.SelectBrush;

            if (bsh01 != null) { mmvLight.MainCanvas.Background = bsh01; } else { mmvLight.MainCanvas.Background = Brushes.WhiteSmoke; }
            if (bsh02 != null) { mmvLight.AncestorsTitleDefaultBackground = bsh02; } else { mmvLight.AncestorsTitleDefaultBackground = Brushes.CornflowerBlue; }
            if (bsh03 != null) { mmvLight.TitleDefaultBackground = bsh03; } else { mmvLight.TitleDefaultBackground = Brushes.Crimson; }
            if (bsh04 != null) { mmvLight.ChildTitleDefaultBackground = bsh04; } else { mmvLight.ChildTitleDefaultBackground = Brushes.Black; }
            if (bsh05 != null) { mmvLight.TitleDefaultForeground = bsh05; } else { mmvLight.TitleDefaultForeground = Brushes.White; }
            if (bsh06 != null) { mmvLight.TitleLinkStroke = bsh06; } else { mmvLight.TitleLinkStroke = Brushes.Black; }
            if (bsh07 != null) { mmvLight.TitleDefaultActiveBrush = bsh07; } else { mmvLight.TitleDefaultActiveBrush = Brushes.SandyBrown; }
            if (bsh08 != null) { mmvDark.MainCanvas.Background = bsh08; } else { mmvDark.MainCanvas.Background = BrushManager.GetBrush("BlackSmoke"); }
            if (bsh09 != null) { mmvDark.AncestorsTitleDefaultBackground = bsh09; } else { mmvDark.AncestorsTitleDefaultBackground = Brushes.BurlyWood; }
            if (bsh10 != null) { mmvDark.TitleDefaultBackground = bsh10; } else { mmvDark.TitleDefaultBackground = Brushes.LightBlue; }
            if (bsh11 != null) { mmvDark.ChildTitleDefaultBackground = bsh11; } else { mmvDark.ChildTitleDefaultBackground = Brushes.White; }
            if (bsh12 != null) { mmvDark.TitleDefaultForeground = bsh12; } else { mmvDark.TitleDefaultForeground = Brushes.Black; }
            if (bsh13 != null) { mmvDark.TitleLinkStroke = bsh13; } else { mmvDark.TitleLinkStroke = Brushes.White; }
            if (bsh14 != null) { mmvDark.TitleDefaultActiveBrush = bsh14; } else { mmvDark.TitleDefaultActiveBrush = Brushes.Crimson; }

            App.WorkspaceConfigManager.Set("Mindmap-Light-ThemeMapBackground", BrushManager.GetRealEnName(bsh01));
            App.WorkspaceConfigManager.Set("Mindmap-Light-ThemeParentTitleBackground", BrushManager.GetRealEnName(bsh02));
            App.WorkspaceConfigManager.Set("Mindmap-Light-ThemeCurrentTitleBackground", BrushManager.GetRealEnName(bsh03));
            App.WorkspaceConfigManager.Set("Mindmap-Light-ThemeSubTitleBackground", BrushManager.GetRealEnName(bsh04));
            App.WorkspaceConfigManager.Set("Mindmap-Light-ThemeTitleForeground", BrushManager.GetRealEnName(bsh05));
            App.WorkspaceConfigManager.Set("Mindmap-Light-ThemeTitleLinkStroke", BrushManager.GetRealEnName(bsh06));
            App.WorkspaceConfigManager.Set("Mindmap-Light-ThemeTitleSelectionBox", BrushManager.GetRealEnName(bsh07));
            App.WorkspaceConfigManager.Set("Mindmap-Dart-ThemeMapBackground", BrushManager.GetRealEnName(bsh08));
            App.WorkspaceConfigManager.Set("Mindmap-Dart-ThemeParentTitleBackground", BrushManager.GetRealEnName(bsh09));
            App.WorkspaceConfigManager.Set("Mindmap-Dart-ThemeCurrentTitleBackground", BrushManager.GetRealEnName(bsh10));
            App.WorkspaceConfigManager.Set("Mindmap-Dart-ThemeSubTitleBackground", BrushManager.GetRealEnName(bsh11));
            App.WorkspaceConfigManager.Set("Mindmap-Dart-ThemeTitleForeground", BrushManager.GetRealEnName(bsh12));
            App.WorkspaceConfigManager.Set("Mindmap-Dart-ThemeTitleLinkStroke", BrushManager.GetRealEnName(bsh13));
            App.WorkspaceConfigManager.Set("Mindmap-Dart-ThemeTitleSelectionBox", BrushManager.GetRealEnName(bsh14));
        }

        private void btnRestoreLightTheme_Click(object sender, RoutedEventArgs e)
        {
            cmbLightThemeMapBackground.SelectedIndex = -1;
            cmbLightThemeParentTitleBackground.SelectedIndex = -1;
            cmbLightThemeCurrentTitleBackground.SelectedIndex = -1;
            cmbLightThemeSubTitleBackground.SelectedIndex = -1;
            cmbLightThemeTitleForeground.SelectedIndex = -1;
            cmbLightThemeTitleLinkStroke.SelectedIndex = -1;
            cmbLightThemeTitleSelectionBox.SelectedIndex = -1;
        }

        private void btnRestoreDarkTheme_Click(object sender, RoutedEventArgs e)
        {
            cmbDartThemeMapBackground.SelectedIndex = -1;
            cmbDartThemeParentTitleBackground.SelectedIndex = -1;
            cmbDartThemeCurrentTitleBackground.SelectedIndex = -1;
            cmbDartThemeSubTitleBackground.SelectedIndex = -1;
            cmbDartThemeTitleForeground.SelectedIndex = -1;
            cmbDartThemeTitleLinkStroke.SelectedIndex = -1;
            cmbDartThemeTitleSelectionBox.SelectedIndex = -1;
        }
    }
}
